﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        任务执行记录
    </title>
    <meta name="description" content="">
    <meta name="author" content="">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <!-- #CSS Links -->
    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.css">

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production-plugins.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.css">

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.css">

    <!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/demo.css">

    <!-- #FAVICONS -->
    <link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
    <link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

    <!-- #GOOGLE FONT -->
    <link rel="stylesheet" href="css/open-sans.css" type="text/css">

    <!-- #APP SCREEN / ICONS -->
    <link rel="apple-touch-icon" href="img/splash/sptouch-icon-iphone.png">
    <link rel="apple-touch-icon" sizes="76x76" href="img/splash/touch-icon-ipad.png">
    <link rel="apple-touch-icon" sizes="120x120" href="img/splash/touch-icon-iphone-retina.png">
    <link rel="apple-touch-icon" sizes="152x152" href="img/splash/touch-icon-ipad-retina.png">

    <!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!-- Startup image for web apps -->
    <link rel="apple-touch-startup-image" href="img/splash/ipad-landscape.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
    <link rel="apple-touch-startup-image" href="img/splash/ipad-portrait.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
    <link rel="apple-touch-startup-image" href="img/splash/iphone.png" media="screen and (max-device-width: 320px)">
    <link href="appcss/Common.css" rel="stylesheet" />
</head>
<body class="desktop-detected minified">

    <!-- #MAIN PANEL -->
    <div id="main" role="main">

        <!-- RIBBON -->
        <div id="ribbon">


            <span class="ribbon-button-alignment">
                <span class="btn btn-ribbon"><i class="fa fa-home"></i></span>
            </span>

            <!-- breadcrumb -->
            <ol class="breadcrumb">
                <li><a href="SchedulingTaskManagement.html">调度任务管理</a></li>
                <li>任务执行记录</li>
            </ol>
            <!-- end breadcrumb -->

        </div>
        <!-- END RIBBON -->
        <!-- MAIN CONTENT -->
        <div id="content">
            <div class="row hidden">
                <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                    <h1 class="page-title txt-color-blueDark">
                        <i class="fa fa-edit fa-fw "></i>
                        主页
                        <span>
                            >
                            任务执行记录
                        </span>
                    </h1>
                </div>

            </div>

            <!-- widget grid -->
            <section id="widget-grid" class="">

                <!-- row -->
                <div class="row">

                    <!-- NEW WIDGET START -->
                    <!-- NEW WIDGET START -->
                    <article class="col-sm-12 col-md-12 ">

                        <!-- Widget ID (each widget will need unique ID)-->
                        <div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false"
                             data-widget-editbutton="false">
                            <header>
                                <h2>任务执行记录</h2>

                            </header>

                            <!-- widget div-->
                            <div>

                                <!-- widget edit box -->
                                <div class="jarviswidget-editbox">
                                    <!-- This area used as dropdown edit box -->

                                </div>
                                <!-- end widget edit box -->
                                <!-- widget content -->
                                <div class="widget-body no-padding">

                                    <!-- Success states for elements -->

                                    <form action="#" class="smart-form">
                                        <fieldset>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 任务 </label>
                                                </section>
                                                <section class="col col-5">
                                                    <label class="input"> <input type="text" id="TaskName" disabled="disabled" /></label>
                                                </section>
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 数据服务 </label>
                                                </section>
                                                <section class="col col-5">
                                                    <label class="input"><input type="text" id="ServiceName" disabled="disabled" /></label>
                                                </section>
                                            </div>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 数据源 </label>
                                                </section>
                                                <section class="col col-5">
                                                    <label class="input"> <input type="text" id="SourceName" disabled="disabled" /></label>
                                                </section>
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 数据表 </label>
                                                </section>
                                                <section class="col col-5">
                                                    <label class="input"><input type="text" id="TableName" disabled="disabled" /></label>
                                                </section>
                                            </div>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 完成事件 </label>
                                                </section>
                                                <section class="col col-5">
                                                    <label class="input"><input type="text" id="CompletedEvent" disabled="disabled" /></label>
                                                </section>
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"></label>
                                                </section>
                                                <section class="col col-5">
                                                    <div class="inline-group">
                                                        <label class="checkbox">
                                                            <input type="checkbox" id="EnableDataVerificationOption" disabled="disabled">
                                                            <i></i>启用数据审核
                                                        </label>
                                                        <label class="checkbox">
                                                            <input type="checkbox" id="EnableCodeConversionOption" disabled="disabled">
                                                            <i></i>启用编码转换
                                                        </label>
                                                    </div>
                                                </section>
                                            </div>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 执行模式 </label>
                                                </section>
                                                <section class="col col-10">
                                                    <label class="label" id="RunMode" style="color: blue; line-height: 32px;">加载中......</label>
                                                </section>
                                            </div>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;">模式</label>
                                                </section>
                                                <section id="RunModes" class="col col-5"></section>
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;">参数</label>
                                                </section>
                                                <section id="Patameters" class="col col-5"></section>
                                            </div>
                                            <div class="row">
                                                <section class="col col-1">
                                                    <label class="label" style="line-height: 32px;"> 时间范围 </label>
                                                </section>
                                                <section class="col col-2">
                                                    <label class="input">
                                                        <i class="icon-append fa fa-calendar"></i>
                                                        <input type="text" id="BeginDate" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" placeholder="开始日期" />
                                                    </label>
                                                </section>
                                                <section class="col col-2">
                                                    <label class="input">
                                                        <i class="icon-append fa fa-calendar"></i>
                                                        <input type="text" placeholder="截止日期" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" id="EndDate" />
                                                    </label>
                                                </section>
                                                <section class="col col-1">
                                                    <label class="input">
                                                        <a class="btn btn-primary" onclick="SearchData()" style="padding: 6px 12px !important;"
                                                           href="javascript:void(0);">立即查询</a>
                                                    </label>
                                                </section>
                                            </div>
                                        </fieldset>

                                        <fieldset>
                                            <section>
                                                <label class="label">查询结果</label>
                                                <table class="table table-bordered table-hover" id="datalist-table">
                                                    <thead>
                                                        <tr>
                                                            <th>批次号</th>
                                                            <th>执行时间</th>
                                                            <th>获取数据</th>
                                                            <th>类型审核失败</th>
                                                            <th>数据审核失败</th>
                                                            <th>数据入库失败</th>
                                                            <th>编码转换失败</th>
                                                            <th>数据插入成功</th>
                                                            <th>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody></tbody>
                                                </table>
                                            </section>
                                        </fieldset>

                                    </form>
                                    <!--/ Success states for elements -->
                                </div>
                                <!-- end widget content -->
                            </div>
                            <!-- end widget div -->
                        </div>
                        <!-- end widget -->
                    </article>
                </div>

                <!-- end row -->

            </section>
        </div>
        <!-- END MAIN CONTENT -->
    </div>


    <!--================================================== -->
    <!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)
    <script data-pace-options='{ "restartOnRequestAfter": true }' src="js/plugin/pace/pace.min.js"></script>-->
    <!-- #PLUGINS -->
    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->


    <script src="js/libs/jquery-2.1.1.min.js"></script>
    <script src="js/libs/jquery-ui-1.10.3.min.js"></script>
    <!-- BOOTSTRAP JS -->
    <script src="js/bootstrap/bootstrap.min.js"></script>

    <!-- IMPORTANT: APP CONFIG -->
    <script src="js/app.config.js"></script>


    <!-- CUSTOM NOTIFICATION -->
    <script src="js/notification/SmartNotification.min.js"></script>

    <!-- JARVIS WIDGETS -->
    <script src="js/smartwidgets/jarvis.widget.min.js"></script>


    <!-- SPARKLINES -->
    <script src="js/plugin/sparkline/jquery.sparkline.min.js"></script>

    <!-- JQUERY MASKED INPUT -->
    <script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>


    <!-- JQUERY UI + Bootstrap Slider -->
    <script src="js/plugin/bootstrap-slider/bootstrap-slider.min.js"></script>
    <script src="js/app.min.js"></script>
    <script src="appjs/Helper.js"></script>
    <script src="appjs/Common.js"></script>

    <script src="js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="js/plugin/datatables/dataTables.colVis.min.js"></script>
    <script src="js/plugin/datatables/dataTables.tableTools.min.js"></script>
    <script src="js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="js/plugin/datatable-responsive/datatables.responsive.min.js"></script>
    <script src="js/plugin/My97DatePicker/WdatePicker.js"></script>
    <script src="js/moment.js"></script>
    <script>
        var draw = 0;
        var table;
        var taskId = GetQueryString("taskId");
        var SearchData = function () {
            if (draw != 0) {
                table.fnDraw();
            } else {
                initializationDataTable();
            }
        }
        $(function () {
            var d = new Date();
            var vYear = d.getFullYear();
            var vMon = d.getMonth() + 1;
            var vDay = d.getDate();
            var begindata = vYear + "-" + (vMon < 10 ? "0" + vMon : vMon) + "-01";
            var enddata = "";
            if (parseInt(vMon) < 12) {
                enddata = vYear + "-" + ((vMon + 1) < 10 ? ("0" + (parseInt(vMon) + 1)) : (parseInt(vMon) + 1)) + "-01";
            } else {
                enddata = (parseInt(vYear) + 1) + "-" + "01" + "-01";
            }
            $("#BeginDate").val(begindata);
            $("#EndDate").val(enddata);
            SearchData();
            getTaskInfo();
        });
        var getTaskInfo = function () {
            $.ajax({
                url: apiUrl,
                data: {
                    "sys:sno": "Task",
                    "sys:act": "Get",
                    "TaskId": taskId
                },
                dataType: "json",
                success: function (data) {
                    if (data.IsSccuess) {
                        $("#SourceName").val(data.Data.DtSourceText);//名称
                        $("#TableName").val(data.Data.DtTableText);
                        $("#TaskName").val(data.Data.Name);
                        $("#ServiceName").val(data.Data.DtSerText);
                        if (data.Data.EnableDataVerification) {
                            $("#EnableDataVerificationOption").attr("checked", "checked");
                        }
                        if (data.Data.EnableCodeConversion) {
                            $("#EnableCodeConversionOption").attr("checked", "checked");
                        }
                        $("#RunMode").html(GetRunMode(data.Data.RunMode));
                        $("#CompletedEvent").val(data.Data.CompletedEvent);
                        $("#RunModes").html(GetRunModes(data));
                        PatametersTable(data.Data.Patameters);
                    } else {
                        if (IsLogined(data.ErrorCode)) {
                            alert(data.Message);
                        }
                    }
                },
                beforeSend: function () {
                    // $("btn_login").html("登录中...");
                }
            });
        }
        var PatametersTable = function (data) {

            var str = "<table class=\"table table-bordered table-hover\" ><thead><tr>";
            str += "<th>参数名称</th><th>参数类型</th><th>参数值</th></tr></thead> <tbody>";
            for (var i = 0; i < data.length; i++) {
                str += "<tr>";
                str += ("<td>" + data[i].Name + "</td><td>");
                switch (data[i].ValueType) {
                    case 1:
                        str += "具体值";
                        break;
                    case 2:
                        str += "表达式";
                        break;
                    case 3:
                        str += "循环数组";
                        break;
                }
                str += "</td>";
                str += ("<td>" + data[i].ValueString + "</td>");
                str += "</tr>";
            }
            str += "</tbody></table>";
            $("#Patameters").html(str);
        }
        var initializationDataTable = function () {
            table = $('#datalist-table').dataTable({
                "autoWidth": true,
                "bLengthChange": false,
                "oLanguage": {
                    "sProcessing": "正在加载数据...",
                    "sZeroRecords": "没有您要搜索的内容",
                    "sInfo": "从_START_ 到 _END_ /共 _TOTAL_ 条",
                    "sInfoEmpty": "记录数为0",
                    "sInfoFiltered": "(全部记录数 _MAX_  条)",
                    "sInfoPostFix": "",
                    "sUrl": "",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上一页",
                        "sNext": "下一页",
                        "sLast": "末页"
                    }
                },
                ordering: false,
                bProcessing: true,
                bStateSave: true,
                serverSide: true,
                searching: false,
                aLengthMenu: [25],
                "ajax": {
                    url: apiUrl,
                    "dataSrc": function (json) {
                        if (json.IsSccuess) {
                            var newjson = new Array();
                            for (var i = 0; i < json.Data.Items.length; i++) {
                                var thisobj = json.Data.Items[i];
                                var detaile = "<a href=\"SchedulingTaskExecutionDetails.html?batchId=" + thisobj.BatchId + "&taskId=" + taskId + "\">" + "查看</a>";
                                newjson.push({ "num": thisobj.BatchId, "excuteTime": thisobj.CreatedTime, "codenum": thisobj.CodeConvertFailureCount, "getNum": thisobj.DataCount, "typenum": thisobj.TypeVerifyFailureCount, "datanum": thisobj.DataVerifyFailureCount, "rulenum": thisobj.InsertFailureCount, "enterNum": thisobj.InsertSuccessCount, "option": detaile });
                            }
                            return newjson;
                        } else {
                            if (IsLogined(json.ErrorCode)) {
                                alert("失败（" + "错误代码：" + json.ErrorCode + "，错误信息：" + json.Message + ")");
                            }
                        }
                        return {};
                    },
                    "data": function (d) {
                        if (draw == 0) {
                            var cookiend = getCookie("SchedulingTaskExecutionRecord_End");
                            if ((cookiend != null) && (cookiend != ""))
                                $("#EndDate").val(cookiend);
                            var cookiebegin = getCookie("SchedulingTaskExecutionRecord_Begin");
                            if ((cookiebegin != null) && (cookiebegin != ""))
                                $("#BeginDate").val(cookiebegin);

                        }
                        setCookie("SchedulingTaskExecutionRecord_End", $("#EndDate").val(), 1);
                        setCookie("SchedulingTaskExecutionRecord_Begin", $("#BeginDate").val(), 1);
                        draw = d.draw;
                        return $.extend({}, { "sys:sno": "ETL" }, { "sys:act": "GetTaskExecuteRecordList" }, { "TaskId": taskId }, { "BeginTime": $("#BeginDate").val() }, { "EndTime": $("#EndDate").val() }, { "draw": d.draw }, { "length": d.length }, { "Page": parseInt(d.start / d.length) });
                    }
                },
                columns: [
                    { data: 'num' },
                    { data: 'excuteTime' },
                    { data: 'getNum' },
                    { data: 'typenum' },
                    { data: 'datanum' },
                    { data: 'rulenum' },
                    { data: 'codenum' },
                    { data: 'enterNum' },
                    { data: 'option' }

                ]
            });
        }
        var GetRunModes = function (data) {
            var str = "";
            switch (data.Data.RunMode) {
                case 1:
                    //定时器
                    str += "<label class=\"label\">开始时间</label>";
                    str += ("<label class=\"input\"><input  type=\"text\" disabled=\"disabled\" value=\"" + data.Data.RunModes[0].TimerBeginTime + "\" ></label>");
                    str += "<label class=\"label\">间隔</label>";
                    str += ("<label class=\"input\"><input  type=\"text\" disabled=\"disabled\" value=\"" + data.Data.RunModes[0].TimerInterval + GetTimerIntervalModeName(data.Data.RunModes[0].TimerIntervalMode) + "\" ></label>");
                    break;
                case 2:
                    //闹钟
                    str += "<table class=\"table table-bordered table-hover\" ><thead><tr>";
                    str += "<th>类型</th><th>间隔</th></tr></thead> <tbody>";
                    for (var i = 0; i < data.Data.RunModes.length; i++) {
                        str += "<tr>";
                        str += ("<td>" + GetClockTypeName(data.Data.RunModes[i].AlarmMode) + "</td>");
                        var tempstr = data.Data.RunModes[i].AlarmClock.replace(/-/g, "/");
                        var nowdate = new Date(tempstr);
                        //var nowdate = new Date("2016-05-11 18:00".replace(/-/g, "/"));
                        switch (data.Data.RunModes[i].AlarmMode) {
                            case 1:
                                str += ("<td>" + nowdate.format("MM月dd日 HH时mm分") + "</td>");
                                break;
                            case 2:
                                str += ("<td>" + nowdate.format("dd日 HH时mm分") + "</td>");
                                break;
                            case 3:
                                str += ("<td>" + nowdate.getWeek() + nowdate.format(" HH时mm分") + "</td>");
                                break;
                            case 4:
                                str += ("<td>" + nowdate.format(" HH时mm分") + "</td>");
                                break;
                        }
                        str += "</tr>";
                    }
                    str += "</tbody></table>";
                    break;
                case 4:
                    //事件触发
                    str += "<label class=\"label\">事件名称</label>";
                    str += ("<label class=\"input\"><input  type=\"text\" disabled=\"disabled\" value=\"" + data.Data.RunModes[0].EventName + "\" ></label>");
                    break;
            }
            console.log(str);
            return str;

        }
        var GetClockTypeName = function (typeId) {
            var str = "";
            switch (typeId) {
                case 1:
                    str = "每年"; break;
                case 2:
                    str = "每月"; break;
                case 3:
                    str = "每周"; break;
                case 4:
                    str = "每天"; break;
                default:
                    str = "未找到"; break;
            }
            return str;
        }
        var GetTimerIntervalModeName = function (typeId) {
            var str = "";
            switch (typeId) {
                case 1:
                    str = "天"; break;
                case 2:
                    str = "小时"; break;
                case 3:
                    str = "分"; break;
                default:
                    str = "未找到"; break;
            }
            return str;
        }
        var GetRunMode = function (runType) {
            var str = "";
            switch (runType) {

                case 1: str = "定时器"; break;
                case 2: str = "闹钟"; break;
                case 3: str = "手动"; break;
                case 4: str = "事件触发"; break;
                default: str = "未知"; break;
            }
            return str;
        }
    </script>


</body>
</html>
